package com.wzy.springstrage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * @Auther: wzy
 * @Date: 2021/12/11/11:59
 * @Description:
 */
@Component
public class FormFaasSubmitHandler implements FormSubmitHandler<Serializable> {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public String getSubmitType() {
        return "fass";
    }

    @Override
    public CommonPairResponse<String, Serializable> handleSubmit(FormSubmitRequest request) {
        logger.info("FaaS 模式的提交：userId={}, formInput={}", request.getUserId(), request.getFormInput());

        // 进行 FaaS 函数调用，并获得业务方返回的提示信息和业务数据
        CommonPairResponse<String, Serializable> response = faasSubmitData(request);

        return response;
    }

    private CommonPairResponse<String, Serializable> faasSubmitData(FormSubmitRequest request) {
        return CommonPairResponse.success(request, 200);
    }
}
